<template>
    <div class="priceSet-view">
        <el-dialog :title="titleText" :visible.sync="dialogFormVisible" :close-on-click-modal="closeOnClickModal" :close-on-press-escape="closeOnPressEscape" width="10%" :show-close="showimg">
            <div slot="footer" class="dialog-footer">
                <el-button class="cancel-button"  @click="closeForm" >取 消</el-button>
                <el-button class="sure-button" type="primary" @click="addstruct">保 存</el-button>
            </div>
            <div>
                <el-form :model="dynamicValidateForm" ref="dynamicValidateForm">
                    <el-table
                            :data="dynamicValidateForm.list"
                            style="width: 100%">
                        <el-table-column
                                prop="subscribeNum"
                                label="类型"
                                width="180">
                        </el-table-column>
                        <el-table-column
                                v-if="this.priceType==2"
                                prop="subscribeRemark"
                                label="购买次数限制"
                                width="180">
                        </el-table-column>
                        <el-table-column
                                label="开通价格/元">
                            <template slot-scope="scope">
                                <div class="priceSet-view-inputb">
                                    <el-form-item :prop="'list.' + scope.$index + '.subscribeAmount'"
                                            :rules="[
                                                { required: true, message: '金额不能为空'},
                                                { type: 'number', message: '金额必须为数字值'},
                                                {validator: positiveInteger, trigger: 'blur'}
                                            ]" >
                                        <el-input type="number" v-model.number="list[scope.$index].subscribeAmount" class="priceSet-view-input-input" placeholder="请输入内容"></el-input>
                                    </el-form-item>
                                </div>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-form>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "priceSet",
        data(){
            return{
                closeOnClickModal:false,
                closeOnPressEscape:false,
                domains: [{
                    value:0
                }],
                tableWidth:300,
                organizationId: this.$store.getters.userData.userMsg.id,//组织id
                priceType:"",
                titleText:"",
                showimg:false,
                ruleForm:{
                    oneDayAmount:0,
                    oneMonthAmount:0,
                },
                rules: {
                },

                dynamicValidateForm:{
                    list:[
                    ]
                }
            }
        },
        props:{
            dialogFormVisible: {
                type: Boolean
            },
            linkerIds:{
                type: String
            },
            priceSetType:{
                type: Number
            }
        },
        watch: {
            priceSetType:{
                handler(newValue, oldValue) {
                    this.priceType=newValue
                    this.getlist();
                    if(newValue==1){
                        this.titleText="VIP价格设置"
                        this.tableWidth=480
                    }else {
                        this.titleText="设置开通价格"
                        this.tableWidth=300
                    }
                    console.log(this.priceType)
                }

            }},
        mounted(){
            this.getlist();
        },
        methods: {

            //正整数判断，不包含0
            positiveInteger(rule, value, callback) {
                debugger
                if (value === '') {
                    callback(new Error('金额不能为空'));
                } else {
                    // var pattern = /^\+?[1-9][0-9]*$/; //输入框已经限制了必须是数字，这里只判断是否小于或等于0即可
                    if (value <= 0) {
                        callback(new Error('金额必须为正整数！'));
                    }
                    callback();
                }
            },

            closeForm() {
                console.log("aaaaaaa")
                this.$emit("close");
            },
            addstruct(){
                let _this = this;
                if(this.priceSetType==1){
                    let params={
                        // type:this.priceSetType,
                        oneMonthAmount:this.list[0].subscribeAmount,
                        trimesterAmount:this.list[1].subscribeAmount,
                        twelveMonthAmount:this.list[2].subscribeAmount,
                    }
                    console.log(this.list)
                    _this.Api.setting.distSetAllHouseVIPAmount(params).then((data)=>{
                        this.$emit("close");
                        console.log("wowooooooooooowowoowowoowoowowoow",data)
                    })
                }else {
                    let params={
                        linkerIds:this.linkerIds,
                        // type:this.priceSetType,
                        oneDayAmount:this.list[0].subscribeAmount,
                        oneMonthAmount:this.list[1].subscribeAmount,
                        trimesterAmount:this.list[2].subscribeAmount,
                        sixMonthsAmount:this.list[3].subscribeAmount,
                        twelveMonthAmount:this.list[4].subscribeAmount,
                    }
                    console.log(this.list)
                    _this.Api.setting.distSetAllHouseAmount(params).then((data)=>{
                        this.$emit("close");
                        console.log("wowooooooooooowowoowowoowoowowoow",data)
                    })
                }


            },
            getlist(){
                let _this = this;
                if(this.priceSetType==1){
                    _this.Api.setting.distSeeNewHouseVIPDefaultAmount().then((data)=>{
                        console.log("wowooooooooooowowoowowoowoowowoow",data)
                        _this.list=data.data;
                        _this.dynamicValidateForm.list=data.data;
                        console.log("wowooooooooooowowoowowoowoowowoow", _this.dynamicValidateForm)
                    })
                }else {
                    _this.Api.setting.distSeeNewHouseDefaultAmount().then((data)=>{
                        console.log("wowooooooooooowowoowowoowoowowoow",data)
                        _this.list=data.data;
                        _this.dynamicValidateForm.list=data.data;
                        console.log("wowooooooooooowowoowowoowoowowoow", _this.dynamicValidateForm)
                    })
                }


            }
        }
    }
</script>
<style>
    .priceSet-view .el-dialog--small {
        width:702px;
    }
    .priceSet-view .el-input__inner{
        height: 32px;
    }
</style>
<style scoped >
    .priceSet-view{

    }
    .priceSet-view .priceSet-view-inputb{
        width:138px;
        height:52px;
        display: flex;
    }
    .priceSet-view-input-input{
        align-self: center;
    }
</style>